package com.java.wysnstudy.cc;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Test0111 {
    public static void main(String[] args) {
/*
        int[][] clips = new int[][]{{0, 2}, {4, 6}, {8, 10}, {1, 9}, {1, 5}, {5, 9}};
*/
        int [][] clips = {{0,1},{6,8},{0,2},{5,6},{0,4},{0,3},{6,7},{1,3},{4,7},{1,4},{2,5},{2,6},{3,4},{4,5},{5,7},{6,9}};

        int number = 9;
        System.out.println(videoStitching(clips, number));
    }

    public static int videoStitching(int[][] clips, int time) {
        Map<Integer, Integer> map = new HashMap<>();
        //去除初始值同类型，保留value最大值
        for (int i = 0; i < clips.length; i++) {
            int[] beg = clips[i];
            Integer integer = map.get(beg[0]);
            if (integer != null) {
                if (beg[1] > integer) {
                    map.put(beg[0], beg[1]);
                }
            } else {
                map.put(beg[0], beg[1]);
            }
        }
        map.forEach((k, v) -> System.out.println(k + "======" + v));

        Integer beigin = map.get(0);
        if (beigin==null){
            return -1;
        }
        int end=0;
        int count = 0;
        while (1==count) {
            for (int i=beigin;end<beigin;i--){
                Integer integer = map.get(i);
                if (integer!=null){
                    if (integer>beigin){
                        beigin=integer;
                    }
                }

            }

        }
        return count;
    }
}
